using ComponentAce.Compression.Libs.zlib;
using System;
using System.IO;
namespace MicroMsg.Common.Algorithm
{
	public class Zlib
	{
		private const string TAG = "MicroMsg.Zlib";
		public static bool Compress(byte[] inBuf, ref byte[] outBuf)
		{
			bool result;
			try
			{
				MemoryStream memoryStream = new MemoryStream();
				ZOutputStream zOutputStream = new ZOutputStream(memoryStream, -1);
				zOutputStream.Write(inBuf, 0, inBuf.Length);
				zOutputStream.Flush();
				memoryStream.Flush();
				outBuf = memoryStream.ToArray();
				memoryStream.Close();
				return true;
			}
			catch (IOException)
			{
				result = false;
			}
			return result;
		}
		public static bool Decompress(byte[] inBuf, int unCompressLen, ref byte[] outBuf)
		{
			bool result;
			try
			{
				MemoryStream memoryStream = new MemoryStream();
				ZOutputStream zOutputStream = new ZOutputStream(memoryStream);
				zOutputStream.Write(inBuf, 0, inBuf.Length);
				zOutputStream.Flush();
				memoryStream.Flush();
				outBuf = memoryStream.ToArray();
				memoryStream.Close();
				return true;
			}
			catch (IOException)
			{
				result = false;
			}
			return result;
		}
	}
}
